package com.situ.hospital.service.impl;

import com.situ.hospital.dao.ICategoryDAO;
import com.situ.hospital.dao.Impl.CategoryDAOImpl;
import com.situ.hospital.pojo.Category;
import com.situ.hospital.pojo.query.CategoryQuery;
import com.situ.hospital.service.ICategoryService;
import com.situ.hospital.util.PageResult;

import java.util.List;

public class CategoryServiceImpl implements ICategoryService {

    private ICategoryDAO categoryDAO = new CategoryDAOImpl();

    @Override
    public List<Category> selectAll() {
        return categoryDAO.selectAll();
    }

    @Override
    public PageResult<Category> selectByPage(CategoryQuery categoryQuery) {
        List<Category> list = categoryDAO.selectByPage(categoryQuery);
        int totalCount = categoryDAO.selectTotalCount(categoryQuery);
        return new PageResult<>(0, "", totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        categoryDAO.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        for(String id : ids) {
            categoryDAO.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Category category) {
        categoryDAO.add(category);
    }

    @Override
    public Category selectById(int id) {
        return categoryDAO.selectById(id);
    }

    @Override
    public void update(Category category) {
        categoryDAO.update(category);
    }
}
